/**
 * 
 */
package com.darren.befriend.adapters;

import java.util.ArrayList;

import com.darren.befriend.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author ThaoQuyen
 * 
 */
public class UniversityAdapter extends BaseAdapter {

	private ArrayList<String> mUniversity;
	private LayoutInflater mInflater;

	public UniversityAdapter(Context context, ArrayList<String> university) {
		super();
		this.mUniversity = university;
		this.mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub

		if (mUniversity != null) {

			return mUniversity.size();
		}

		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return mUniversity.get(pos);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int pos, View view, ViewGroup arg2) {
		// TODO Auto-generated method stub

		ViewHolder holder = null;
		String item = mUniversity.get(pos);
		if (view == null) {

			holder = new ViewHolder();
			view = mInflater
					.inflate(R.layout.layout_university_list_item, null);
			holder.university = (TextView) view
					.findViewById(R.id.university_item_text);

			view.setTag(holder);
		} else {

			holder = (ViewHolder) view.getTag();
		}

		holder.university.setText(item);
		return view;
	}

	private class ViewHolder {

		TextView university;
	}

	@SuppressWarnings("unchecked")
	public void setDatas(ArrayList<String> universities) {

		mUniversity = (ArrayList<String>) universities.clone();
	}
}
